<?php
namespace app\index\controller;

use app\admin\model\Product;
use app\admin\model\Specification;
use think\Session;

class Index extends Common
{
    /**
     * @title   产品首页
     * @return mixed
     */
    public function index()
    {
        $product = new Product();
        $index = $product::get(['p_type'=>2])->toArray();
        $this->assign('index',$index);
        $list = $product::all(function($query){
            $query->where('p_type',1);
        })->toarray();
        $this->assign('list',$list);
        return $this->fetch('index/index');
    }

    public function prddetail($id=null)
    {
        $res = Product::get($id);
        $res['spec'] = (new Specification())->field('id,s_name,s_price')->where('s_pid',$id)->select();
        $this->assign('res',$res);
        return $this->fetch('index/goods');
    }

    public function test()
    {
        return $this->fetch('index/testworker');
    }
}
